home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / LOG.C < prev    next >
Text File  |  1991-10-02  |  2KB  |  80 lines

  1. /* ------------ log .c ------------ */
  2.  
  3. #include <stdio.h>
  4. #include "dflat.h"
  5.  
  6. #ifdef INCLUDE_LOGGING
  7.  
  8. #ifndef INCLUDE_HELP
  9.  
  10. char *ClassNames[] = {
  11.     #undef ClassDef
  12.     #define ClassDef(c,b,p,a) #c,
  13.     #include "classes.h"
  14.     NULL
  15. };
  16. #endif
  17.  
  18.  
  19. static char *message[] = {
  20.     #undef DFlatMsg
  21.     #define DFlatMsg(m) " " #m,
  22.     #include "dflatmsg.h"
  23.     NULL
  24. };
  25.  
  26. static FILE *log = NULL;
  27. extern DBOX Log;
  28.  
  29.  
  30. void LogMessages (WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  31. {
  32.     if (log != NULL && message[msg][0] != ' ')
  33.         fprintf(log, "%-20.20s %-12.12s %-20.20s, %5.5ld, %5.5ld\n",
  34.             wnd ? (GetTitle(wnd) ? GetTitle(wnd) : "") : "",
  35.             wnd ? ClassNames[GetClass(wnd)] : "",
  36.             message[msg]+1, p1, p2);
  37. }
  38.  
  39. static int LogProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  40. {
  41.     WINDOW cwnd = ControlWindow(&Log, ID_LOGLIST);
  42.     char **mn = message;
  43.     switch (msg)    {
  44.         case INITIATE_DIALOG:
  45.             AddAttribute(cwnd, MULTILINE | VSCROLLBAR);
  46.             while (*mn)    {
  47.                 SendMessage(cwnd, ADDTEXT, (PARAM) (*mn), 0);
  48.                 mn++;
  49.             }
  50.             SendMessage(cwnd, SHOW_WINDOW, 0, 0);
  51.             break;
  52.         case COMMAND:
  53.             if ((int) p1 == ID_OK)    {
  54.                 int i;
  55.                 for (i = 0; mn[i] != NULL; i++)    {
  56.                     char *cp = TextLine(cwnd, i);
  57.                     mn[i][0] = *cp;
  58.                 }
  59.             }
  60.             break;
  61.         default:
  62.             break;
  63.     }
  64.     return DefaultWndProc(wnd, msg, p1, p2);
  65. }
  66.  
  67. void MessageLog(WINDOW wnd)
  68. {
  69.     if (DialogBox(wnd, &Log, TRUE, LogProc))    {
  70.         if (CheckBoxSetting(&Log, ID_LOGGING))
  71.             log = fopen("DFLAT.LOG", "wt");
  72.         else if (log != NULL)    {
  73.             fclose(log);
  74.             log = NULL;
  75.         }
  76.     }
  77. }
  78.  
  79. #endif
  80.